package com.xijia.wuyouwallet.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.base.BaseActivity;
import com.xijia.wuyouwallet.utils.UrlConfig;

/**
 * Created by Administrator on 2017/7/31 0031.
 */

public class GeneralizeMaterialActivity extends BaseActivity implements View.OnClickListener{

    private ImageView generalizeMaterial_back;
    private ProgressBar generalizeMaterial_progressBar;
    private WebView generalizeMaterial_wv;
    private TextView generalizeMaterial_title;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_generalize_material);
        initView();
    }

    private void initView(){
        generalizeMaterial_back = (ImageView) findViewById(R.id.generalizeMaterial_back);
        generalizeMaterial_back.setOnClickListener(this);
        generalizeMaterial_progressBar = (ProgressBar) findViewById(R.id.generalizeMaterial_progressBar);
        generalizeMaterial_wv = (WebView) findViewById(R.id.generalizeMaterial_wv);
        generalizeMaterial_title = (TextView) findViewById(R.id.generalizeMaterial_title);

        generalizeMaterial_wv.getSettings().setJavaScriptEnabled(true);
        //设置滚动条可见
        setProgressBarIndeterminateVisibility(true);
        init();
        //generalizeMaterial_wv.addJavascriptInterface(new AndroidMessage(), "AndroidMessage");
        generalizeMaterial_wv.loadUrl(UrlConfig.SHARE_MATERIAL_URL);
    }
    private void init() {
        // TODO 自动生成的方法存根
        generalizeMaterial_wv.setWebViewClient(new WebViewClient(){
            //覆写shouldOverrideUrlLoading实现内部显示网页
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO 自动生成的方法存根
                view.loadUrl(url);
                return true;
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                String title=view.getTitle();
                if(title==null){
                    title="";
                }
                generalizeMaterial_title.setText(title);
                super.onPageFinished(view, url);
            }
        });
        generalizeMaterial_wv.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // TODO 自动生成的方法存根
                generalizeMaterial_progressBar.setProgress(newProgress);
                if (newProgress == 100) {
                    generalizeMaterial_progressBar.setVisibility(View.GONE);
                }
                super.onProgressChanged(view, newProgress);
            }
        });
    }


    @Override
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.generalizeMaterial_back:
                finish();
                break;
        }
    }

    /*class AndroidMessage{

        @JavascriptInterface
        public String getUser() {
            //Log.e("info","js号码="+str);
        *//*Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + str);
        intent.setData(data);
        startActivity(intent);*//*
            return MyApp.userData.getData().getUser_id();
        }

        @JavascriptInterface
        public String call(String str) {
            Intent intent = new Intent(Intent.ACTION_DIAL);
            Uri data = Uri.parse("tel:" + str);
            intent.setData(data);
            startActivity(intent);
            return str;
        }
    }*/

}
